package com.pxmeta.app.controller.game;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.pxmeta.app.controller.game.request.DrawDTO;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.AIGCUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/ai")
@Api(value = "AI模块",tags = "AI模块")
public class AIController {

    @SaCheckLogin
    @PostMapping("/draw")
    @ApiOperation("AI绘画")
    public AjaxResult draw(@RequestBody DrawDTO dto){
        String taskId = AIGCUtil.draw(dto.getText(), dto.getStyle());
        Map<String, Object> map = Maps.newHashMap();
        map.put("taskId", taskId);
        return AjaxResult.success(map);
    }


    @SaCheckLogin
    @GetMapping("/getRandomContent")
    @ApiOperation("获取随机内容")
    public AjaxResult getDrawImg(){
        Map<String, Object> map = Maps.newHashMap();

        LinkedList<String> list = Lists.newLinkedList();
        list.add("在电脑前工作，可爱小狗，穿着连帽衫，戴眼镜，全景构图，高清，远视角，8k");
        list.add("微笑，写真，高清摄影，全身，皮肤白皙，美女大学生，白色纱裙，瓜子脸，大眼睛，复杂的细节，绝美，完成度高，高清，高品质，4k");
        list.add("写真，正常摄影，全身，皮肤白皙，古风美女大学生，紫色纱裙，轮廓光线，瓜子脸，大眼睛，优雅武侠风，飘逸，复杂的细节，绝美，完成度高，高清，高品质，极致细节，精美的CG，大师作品，超详细，8k分辨率");
        Collections.shuffle(list);
        map.put("content", list.get(0));
        return AjaxResult.success(map);
    }



    @SaCheckLogin
    @GetMapping("/getImg")
    @ApiOperation("获取绘画结果")
    public AjaxResult getDrawImg(String taskId){
        String img = AIGCUtil.getImg(taskId);
        Map<String, Object> map = Maps.newHashMap();
        map.put("imgUrl", img);
        return AjaxResult.success(map);
    }

}
